import { ajax } from "@/utils/api";
import { GetProductAction, SearchProductAction } from "./action";

// /products?sortBy=createdAt&order=asc&limit=10
export const handleProductService = (payload: GetProductAction) => {
  return ajax.get(`/products`, {
    params: {
      sortBy: payload.sortBy,
      order: payload.order,
      limit: payload.limit,
    },
  });
};
// /products/search?search=node&category=5fa11a0bfbe98b811e09d1ea
export const handleProductSearchService = ({
  payload: { search, category },
}: SearchProductAction) => {
  return ajax.get(`/products/search`, {
    params: {
      search,
      category,
    },
  });
};
